/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.sdt.datastructure;

import com.hp.hpl.jena.vocabulary.RDF;
import edu.yonsei.iwb.ts.TSSearch;
import edu.yonsei.iwb.ts.model.ObjectNode;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;

/**
 *
 * @author JDK
 */
public class TargetInstance {
    
    private String id;
    private String uri;
    private ArrayList<String> typeList;
    private int targetvalue;
    private String realValue;
    
    public TargetInstance(String id, String uri) throws IOException{
        this.id = id;
        this.uri = uri;
        getClassType();
    }
    
    public TargetInstance(String id, String uri, int value) throws IOException{
        this.id = id;
        this.uri = uri;
        this.targetvalue = value;
    }    
    
    private void getClassType() throws IOException{
        this.typeList = new ArrayList();
        ArrayList<ObjectNode> onl = TSSearch.listObjectNode(uri, RDF.type.getURI());
        for (int i = 0; i < onl.size(); i++) {
            ObjectNode objectNode = onl.get(i);
            String classURI = objectNode.getValue();
//            if(classURI.startsWith("http")){
                this.typeList.add(classURI);
//            }            
        }        
    }

    public String getId() {
        return id;
    }

    public String getUri() {
        return uri;
    }

    public int getTargetvalue() {
        return targetvalue;
    }
    
    public void setTargetvalue(int value){
        this.targetvalue = value;
    }
    
    public boolean checkClassType(String classname){
        if(this.typeList.contains(classname)){
            return true;
        }
        return false;
    }
    
    @Override
    public boolean equals(Object o){        
        if(o instanceof TargetInstance){
            TargetInstance ti = (TargetInstance) o;
            if(this.id.equals(ti.getId())){
                return true;
            }
        }        
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + Objects.hashCode(this.id);
        return hash;
    }
    
    @Override
    public String toString(){
        String s = new String();
        s +="id: "+this.id;
        s +="  uri: "+this.uri;
        s +="  value: "+this.targetvalue;
        return s;
    }
    
}
